/*
 * @File: plat_storage_base.h
 * @Description: 存储读写接口定义
 * @Author: wex
 * @email: wexiangis@qq.com
 * @Company:
 * @Date: 2022.11.06
 * @Version: 1.0
 * @Else:
 *      1.下列参数中,名字带path时支持文件夹或文件路径
 *      2.路径必须是绝对路径,且其中字符不能出现'.'或者'..'等路径跳转符号
 */
#ifndef _PLAT_STORAGE_BASE_H_
#define _PLAT_STORAGE_BASE_H_

#include <stdint.h>
#include <stdbool.h>
#include <stdarg.h>

class CPlatStorageBase
{
public:
    virtual ~CPlatStorageBase() {}

    /* 获取绝对路径(补全上级目录),返回最终长度 */
    virtual int32_t GetObsolutePath(const char *childPath, char *retPath, int32_t retPathSize);

    virtual bool IsExist(const char* path);
    virtual bool IsFolder(const char* path);
    virtual int32_t Delete(const char* path);
    virtual int32_t Create(const char* path); /* path最后一个字符为'/'时创建路径 */
    virtual int32_t SizeOf(const char* file);

    virtual int32_t Copy(const char* distPath, const char* srcPath);
    virtual int32_t Move(const char* distPath, const char* srcPath);

    virtual int32_t ReadLine(const char* file, char *data, int32_t size, int32_t lineIndex); /* 行号从1数起,截取内容不包含\r\n */
    virtual int32_t ReadAll(const char* file, char *data, int32_t size);
    virtual int32_t WriteAll(const char* file, const char *data, int32_t size);

    virtual int32_t Append(const char* file, const char *data, int32_t size); /* 往文件追加内容 */

private:
    int32_t DeleteFolder(const char *baseName);
    int32_t CopyFile(const char *distPath, const char *srcPath);
    int32_t CopyFolder(const char *distBaseName, const char *srcBaseName);
};

#endif // _PLAT_STORAGE_BASE_H_
